package com.ruoyi.liborder.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.liborder.domain.LibOrderClass;
import com.ruoyi.liborder.service.ILibOrderClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/lib/class")
public class ClassController extends BaseController {
    @Autowired
    private ILibOrderClassService libOrderClassService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('lib:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibOrderClass libOrderClass) {
        startPage();
        List<LibOrderClass> list = libOrderClassService.selectLibOrderClassList(libOrderClass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('lib:class:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibOrderClass libOrderClass) {
        List<LibOrderClass> list = libOrderClassService.selectLibOrderClassList(libOrderClass);
        ExcelUtil<LibOrderClass> util = new ExcelUtil<>(LibOrderClass.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('lib:class:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId) {
        return AjaxResult.success(libOrderClassService.selectLibOrderClassByClassId(classId));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('lib:class:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibOrderClass libOrderClass) {
        return toAjax(libOrderClassService.insertLibOrderClass(libOrderClass));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('lib:class:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibOrderClass libOrderClass) {
        return toAjax(libOrderClassService.updateLibOrderClass(libOrderClass));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('lib:class:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds) {
        return toAjax(libOrderClassService.deleteLibOrderClassByClassIds(classIds));
    }
}
